package com.chinasoft.goodsManager.servlet;

import com.alibaba.fastjson.JSON;
import com.chinasoft.goodsManager.doamain.Order;
import com.chinasoft.goodsManager.service.OrderService;
import com.chinasoft.goodsManager.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/orderFind")
public class OrderFindServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        String sid = request.getParameter("sid");
        OrderService service = new OrderServiceImpl();
        List<Order> orderList = service.find(sid);
        System.out.println(orderList);
        if(orderList == null){
            response.getWriter().write("0");
        }else {
            String string = JSON.toJSONString(orderList);
            response.getWriter().write(string);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
